import axios from 'axios'
let service = axios.create({
    baseURL: 'http://localhost:4000',//基准路径
    timeout: 10 * 1000 //设置超时
})

// 请求拦截器
service.interceptors.request.use((config) => {
    // 设置请求头
    // config.headers['Authorization'] = 'Bearer' + ' ' + localStorage.getItem('token');
    return config;
}, (error) => {
    return Promise.inject(error);
})

// 响应拦截器
service.interceptors.response.use((res) => {
    return res;
}, (error) => {
    if (error.response.status == 401) {
        console.log('登录过期');
    } else if (error.response.status == 404) {
        console.log('路径出错');
    } else if (error.response.status == 500) {
        console.log('服务器出错');
    }
    return Promise.inject(error);
})

export default service;